package com.zh.equipment.service.impl;


import com.zh.common.dao.UserDao;
import com.zh.common.domain.UserDO;
import com.zh.common.utils.ShiroUtils;
import com.zh.common.utils.StringUtil;
import com.zh.equipment.dao.EquipmentCardDao;
import com.zh.equipment.domain.CardDO;
import com.zh.equipment.service.EquipmentCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class EquipmentCardServiceImpl implements EquipmentCardService {
	@Autowired
	private EquipmentCardDao cardDao;
	@Autowired
	private UserDao userDao;
	
	@Override
	public CardDO get(String id){
		return cardDao.get(id);
	}
	
	@Override
	public List<CardDO> list(Map<String, Object> map){
		return cardDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return cardDao.count(map);
	}
	
	@Override
	public int save(CardDO card){
		UserDO userDO = userDao.get(card.getFamilyUserId());

		card.setId(StringUtil.generalKeyword());
		card.setReleasetime(new Date());
		card.setCreateBy(ShiroUtils.getUser().getName());
		card.setCreateDate(new Date());
		//card.setState("1");//1.正常 2，禁用 3，挂失 4，注销'
		card.setFamilyUserName(userDO.getName());
		return cardDao.save(card);
	}
	
	@Override
	public int update(CardDO card){
		//CardDO cardDO = cardDao.get(card.getId());
		//cardDO.setFamilyUserId(card.getFamilyUserId());
		//cardDO.setFamilyUserName(card.getFamilyUserName());
		//cardDO.setType(card.getType());
		//cardDO.setBalance(card.getBalance());
		//cardDO.setExpiretime(card.getExpiretime());
		//cardDO.set
		UserDO userDO = userDao.get(card.getFamilyUserId());
		card.setFamilyUserName(userDO.getName());
		return cardDao.update(card);
	}
	
	@Override
	public int remove(String id){
		return cardDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return cardDao.batchRemove(ids);
	}
	
}
